var TextCursor = function(width, fillStyle) {
    this.fillStyle = fillStyle || 'rgba(0, 0, 0, .5)';
    this.width = width || 2;
    this.left = 0;
    this.top = 0;
}
TextCursor.prototype = {
    /**
     * 返回光标高度，高度为当前字型的W的高度乘以 1右6分之1
     */
    getHeight: function (ctx) {
        var h = ctx.measureText('W').width;
        return h + h / 6;
    },
    createPath: function (ctx) {
        ctx.beginPath();
        ctx.rect(this.left, this.top, this.width, this.getHeight(ctx));
    },
    erase: function(ctx, imageData) {
        //将没有光标的canvas快照中的一部分（原有光标矩形）复制回canvas，从而擦除已绘图案
        ctx.putImageData(imageData, 0, 0, this.left, this.top, this.width + 1, this.getHeight(ctx) + 1.7);
    },
    draw: function (ctx, left, top) {
        ctx.save();
        this.left = left;
        this.top = top - this.getHeight(ctx) / 2;

        this.createPath(ctx);
        
        ctx.fillStyle = this.fillStyle;
        ctx.fill();

        ctx.restore();
    }
}